package cn.dujc.superkid.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dujc.superkid.R;
import cn.dujc.superkid.bean.ResultsEntity;
import cn.dujc.superkid.bean.UnitResult;

/**
 * Created by Administrator on 2018/10/16 0016.
 */

public class CupUnitTestResultAdapter extends RecyclerView.Adapter<CupUnitTestResultAdapter.ViewHolder> {
    private Context context;
    private List<ResultsEntity> datas;
    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public List<ResultsEntity> getDatas() {
        return datas;
    }

    public void setDatas(List<ResultsEntity> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public CupUnitTestResultAdapter(Context context) {
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_unittest_result, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        ResultsEntity d = datas.get(position);
        holder.contentText.setText("第" + d.getNum() + "题，" + d.getUser() + "人答题，" + d.getAnswerRight() + "人回答正确,正确率" + d.getCorrectRate() + "%，"
                                    +"您的答案是："+d.getUserAnswer()+"，回答"+d.getRow());
        holder.toJx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView contentText;
        TextView toJx;

        public ViewHolder(View itemView) {
            super(itemView);
            contentText = itemView.findViewById(R.id.item_unittest_result_content);
            toJx = itemView.findViewById(R.id.item_unittest_result_to_jiexi);
        }
    }
    public interface OnItemClickListener{
        void onItemClick(int pos);
    }
}
